package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.pojo.Emp;
import org.example.pojo.EmpQueryParam;

import java.util.List;
import java.util.Map;

//@Mapper
//public interface EmpMapper {
//    /**
//     * 查询所有的员工及其对应的部门名称
//     * 不知道为什么调用不了.xml
//     */
////    @Select("select e.*, d.name deptName from emp as e left join dept as d on e.dept_id = d.id\n" +
////            "        where e.name like concat('%',#{name},'%')\n" +
////            "          and e.gender = #{gender}\n" +
////            "          and e.entry_date between #{begin} and #{end}")
//    public List<Emp> list(@Param("name") String name, @Param("gender") Integer gender, @Param("begin") LocalDate begin, @Param("end") LocalDate end);
//}


@Mapper
public interface EmpMapper {
    /**
     * 查询所有的员工及其对应的部门名称
     */
    public List<Emp> list(EmpQueryParam empQueryParam);

    /**
     * 新增员工数据
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    /*根据id批量删除*/
    void deleteByIds(List<Integer> ids);

    Emp getById(Integer id);

    void updateById(Emp emp);

    @MapKey("pos")
    List<Map<String, Object>> countEmpJobData();

    @MapKey("gender")
    List<Map> countEmpGenderData();

    /**
     * Retrieves an employee record from the database based on the provided username and password.
     *
     * @param emp An instance of Emp containing the username and password to query.
     * @return The Emp object containing employee details if a match is found; otherwise, null.
     */
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp getUsernameAndPassword(Emp emp);
}
